//滚动条
//$(function(){
//    //var height=$(window).height()-50;
//    //$('#scroll-left').height(height)
//    //$('#scroll-left').perfectScrollbar();
//})
//toggle侧边栏
(function($){
        var navmy=$('.nav-my'),wshowbg=$('.wshowbg'),wshowhide=$('.wshowhide'), scrollLeft=$('#scroll-left'),wrapper=$('#page-wrapper')

        wshowbg.click(function(){
            if(navmy.width()>=180) {
                if ($('#side-menu>div>li.active')) {
                    $('#side-menu>div>.active ul').attr('class', 'nav nav-second-level collapse');
                    $('#side-menu>div>li').attr('class', ' ')
                    $('.wshowbg').hide();
                }
                wshowhide.show();
                $('.nav >div>li>a').animate({'padding-left':'4px'});
                $('.nav >div>li>a>i').css('font-size', '16px');
                setW(29);
            }
        });
        wshowhide.click(function(){
            $(this).hide();
            wshowbg.show();
            $('.nav >div>li>a').animate({'padding-left':'25px'});
            $('.nav >div>li>a>i').css('font-size', '14px');
            setW(180);
        })
        function setW(num){
            scrollLeft.animate({'width':num+'px'});
            navmy.animate({'width':num+'px'});
            wrapper.animate({'margin-left':num+'px'});
        }
})(jQuery);
    function csMenu(_object, _menu) {
        this.IEventHander = null;
        this.IFrameHander = null;
        this.IContextMenuHander = null;

        this.Show = function(_menu,event){
            var e=event||window.event;
            var pagex=e.pageX||e.clientX+scroll().left;
            var pagey=e.pageY||e.clientY+scroll().top;
            if (e.button == 2){
                if (window.document.all) {
                    this.IContextMenuHander = function(){return false;};
                    document.attachEvent("oncontextmenu", this.IContextMenuHander);
                }
                else{
                    this.IContextMenuHander = document.oncontextmenu;
                    document.oncontextmenu = function(){return false;};
                }

                window.csMenu$Object = this;
                this.IEventHander = function(){window.csMenu$Object.Hide(_menu);};

                if (window.document.all)
                    document.attachEvent("onmousedown", this.IEventHander);
                else
                    document.addEventListener("mousedown", this.IEventHander, false);
                _menu.style.left = pagex+'px';
                _menu.style.top = pagey+'px';
                _menu.style.display = "";
                if (this.IFrameHander){
                    var _iframe = document.getElementById(this.IFrameHander);
                    _iframe.style.left = e.clientX;
                    _iframe.style.top = e.clientY;
                    _iframe.style.height = _menu.offsetHeight;
                    _iframe.style.width = _menu.offsetWidth;
                    _iframe.style.display = "";
                }
            }
        };
        this.Hide = function(_menu) {
            var e = window.event || event;
            var _element = e.srcElement;
            do{
                if (_element == _menu) {
                    return false;
                }
            }
            while ((_element = _element.offsetParent));
            if (window.document.all)
                document.detachEvent("on"+e.type, this.IEventHander);
            else
                document.removeEventListener(e.type, this.IEventHander, false);

            if (this.IFrameHander) {
                var _iframe = document.getElementById(this.IFrameHander);
                _iframe.style.display = "none";
            }
            _menu.style.display = "none";
            if (window.document.all)
                document.detachEvent("oncontextmenu", this.IContextMenuHander);
            else
                document.oncontextmenu = this.IContextMenuHander;
        };
        this.initialize = function(_object, _menu){
            window._csMenu$Object = this;
            var _eventHander = function(){window._csMenu$Object.Show(_menu);};
            _menu.style.position = "absolute";
            _menu.style.display = "none";
            _menu.style.zIndex = "1000000";
            if (window.document.all){
                var _iframe = document.createElement('iframe');
                document.body.insertBefore(_iframe, document.body.firstChild);
                _iframe.id = _menu.id + "_iframe";
                this.IFrameHander = _iframe.id;
                _iframe.style.position = "absolute";
                _iframe.style.display = "none";
                _iframe.style.zIndex = "11";
                _iframe.style.border = "0px";
                _iframe.style.height = "0px";
                _iframe.style.width = "0px";
                _object.attachEvent("onmouseup", _eventHander);
            }else{
                _object.addEventListener("mouseup", _eventHander, false);
            }
        };
        this.initialize(_object, _menu);
    }
    var MM = new csMenu(document.getElementsByClassName("topbar")[0], document.getElementById("Menu1"));
//tab右键关闭
    $('.closeAll').on('click',function(){
        $(this).parent().hide();
        $('.navtab li').not('#home').remove();
        $('.content iframe').not('.home').remove();
        $('.home').show()
        $('#home').attr('class','active');
    });

//刷新当前页面
    $('.refCurrent').on('click',function(){
        var ifrAll=$('iframe');
        for(var i=0;i<ifrAll.length;i++){
            if($(ifrAll[i]).css('display')!='none'){
                ifrAll[i].contentWindow.location.reload();
                $(this).parent().hide();
            };
        }
    });
//关闭其他选项卡；
    $('.closeOt').on('click',function(){
        $(this).parent().hide();
        var ifrAll=$('iframe');
        for(var i=1;i<ifrAll.length;i++){
            if($(ifrAll[i]).css('display')=='none'){
                var liAll=$('.navtab li');
                liAll.not('.active,#home').remove();
                ifrAll[i].remove();
            };
        }
    });
//表格自适应高度；
function  navHeight(){
    var navHeight=$('.topbar').height()+$('.my-nav-top').height();
    return navHeight;
}
function  indexHeight(){
   return $(window).height();
}
$(window).resize(function(){
    indexHeight();
    var ifh=document.getElementsByTagName('iframe');
    for(var i=0;i<ifh.length;i++){
        ifh[i].height=document.documentElement.clientHeight-90;
    }
})